#!/usr/bin/env bash
set -eu
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
set -- ${cli_trace2line:-} "$@"
while getopts a:g OPT; do
  case "$OPT" in
    a)
      arch="$OPTARG"
      ;;
    g)
      gem5=true
      ;;
  esac
done
set_common_vars "$arch" "$gem5"
kernel_dir="${build_dir}/linux-custom"
(
  if "$gem5"; then
    sed -r 's/^.* (0x[^. ]*)[. ].*/\1/' "$common_trace_txt_file"
  else
    sed -r 's/.*pc=//' "$common_trace_txt_file"
  fi
) | \
  xargs "${host_dir}/bin/${arch}-linux-addr2line" -e "${kernel_dir}/vmlinux" -fp | \
  sed -E "s|at ${kernel_dir}/(\./\|)||" | \
  uniq -c \
> "${common_run_dir}/trace-lines.txt"
